﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.Admin;
using DHQGHN.DAL.Models.Admin;

namespace DHQGHN.DAL.BO.Admin
{
    public class GroupInRoleBO : BaseBO
    {
        public const string FIELD_APP_NAME = "AppName";
        public const string FIELD_GROUP_IN_ROLE_ID = "GroupInRoleId";
        public const string FIELD_GROUP_ID = "GroupId";
        public const string FIELD_ROLE_ID = "RoleId";
        public const string FIELD_DESCRIPTIONS = "Descriptions";
        public const string FIELD_IS_ACTIVE = "IsActive";
        public const string FIELD_DATE_CREATED = "DateCreated";
        public const string FIELD_DATE_MODIFIED = "DateModifed";
        public const string FIELD_RECORD_COUNT = "RecordCount";
        public const string FIELD_ROLE_NAME = "RoleName";
        public const string FIELD_GROUP_NAME = "GroupName";
        public const string FIELD_GROUP_CODE = "GroupCode";

        private String _connectionString;

        public GroupInRoleBO(string connString)
        {
            this._connectionString = connString;
        }
        public GroupInRoleBO()
        {
            this._connectionString = Common.ConnectionUtil.DEFAULT_CONN_STRING;
        }

        public GroupInRoleDAO _GroupInRoleDAO;

        public GroupInRoleDAO CreateSQLDAO()
        {
            return new GroupInRoleDAO(_connectionString, DEFAULT_MAPPER_TYPE);
        }

        public DataPage<GroupInRoleModel> GetDynamicListPaging(GroupInRoleModel aModel, int pageSize, int pageIndex)
        {
            try
            {
                _GroupInRoleDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {GroupInRoleModel.FIELD_APP_NAME,FIELD_APP_NAME},
                    {GroupInRoleModel.FIELD_GROUP_IN_ROLE_ID,FIELD_GROUP_IN_ROLE_ID},
                    {GroupInRoleModel.FIELD_GROUP_ID,FIELD_GROUP_ID},
                    {GroupInRoleModel.FIELD_ROLE_ID,FIELD_ROLE_ID},  
                    {GroupInRoleModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {GroupInRoleModel.FIELD_IS_ACTIVE,FIELD_IS_ACTIVE},
                    {GroupInRoleModel.FIELD_DATE_CREATED,FIELD_DATE_CREATED},
                    {GroupInRoleModel.FIELD_DATE_MODIFIED,FIELD_DATE_MODIFIED},
                    {GroupInRoleModel.FIELD_GROUP_NAME,FIELD_GROUP_NAME},
                    {GroupInRoleModel.FIELD_GROUP_CODE,FIELD_GROUP_CODE},
                    {GroupInRoleModel.FIELD_ROLE_NAME,FIELD_ROLE_NAME},
                    {GroupInRoleModel.FIELD_RECORD_COUNT,FIELD_RECORD_COUNT}
                    
                };
                return _GroupInRoleDAO.GetDynamicListPaging(aModel, pageSize, pageIndex, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public GroupInRoleModel GetGroupInRoleById(int? groupInRoleId)
        {
            try
            {
                _GroupInRoleDAO = CreateSQLDAO();

                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {GroupInRoleModel.FIELD_APP_NAME,FIELD_APP_NAME},
                    {GroupInRoleModel.FIELD_GROUP_IN_ROLE_ID,FIELD_GROUP_IN_ROLE_ID},
                    {GroupInRoleModel.FIELD_GROUP_ID,FIELD_GROUP_ID},
                    {GroupInRoleModel.FIELD_ROLE_ID,FIELD_ROLE_ID},  
                    {GroupInRoleModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {GroupInRoleModel.FIELD_IS_ACTIVE,FIELD_IS_ACTIVE},
                    {GroupInRoleModel.FIELD_DATE_CREATED,FIELD_DATE_CREATED},
                    {GroupInRoleModel.FIELD_DATE_MODIFIED,FIELD_DATE_MODIFIED},
                    {GroupInRoleModel.FIELD_GROUP_NAME,FIELD_GROUP_NAME},
                    {GroupInRoleModel.FIELD_GROUP_CODE,FIELD_GROUP_CODE},
                    {GroupInRoleModel.FIELD_ROLE_NAME,FIELD_ROLE_NAME},
                    {GroupInRoleModel.FIELD_RECORD_COUNT,FIELD_RECORD_COUNT}
                };

                return _GroupInRoleDAO.GetById(groupInRoleId, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool createOrUpdateGroupInRole(GroupInRoleModel GroupInRoleModel, int[] listID)
        {
            try
            {
                _GroupInRoleDAO = CreateSQLDAO();
                return _GroupInRoleDAO.createOrUpdateGroupInRole(GroupInRoleModel, listID);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public bool deleteGroupInRole(int[] groupInRoleId)
        {
            try
            {
                _GroupInRoleDAO = CreateSQLDAO();
                return _GroupInRoleDAO.deleteGroupInRole(groupInRoleId);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public List<GroupInRoleModel> GetAllGroupInRoleByGroupId(int groupInRoleId)
        {
            try
            {
                _GroupInRoleDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {  
                    {GroupInRoleModel.FIELD_GROUP_IN_ROLE_ID,FIELD_GROUP_IN_ROLE_ID},
                    {GroupInRoleModel.FIELD_GROUP_ID,FIELD_GROUP_ID},
                    {GroupInRoleModel.FIELD_ROLE_ID,FIELD_ROLE_ID},  
                    {GroupInRoleModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {GroupInRoleModel.FIELD_IS_ACTIVE,FIELD_IS_ACTIVE},
                    {GroupInRoleModel.FIELD_DATE_CREATED,FIELD_DATE_CREATED},
                    {GroupInRoleModel.FIELD_DATE_MODIFIED,FIELD_DATE_MODIFIED},
                    {GroupInRoleModel.FIELD_GROUP_NAME,FIELD_GROUP_NAME},
                    {GroupInRoleModel.FIELD_GROUP_CODE,FIELD_GROUP_CODE},
                    {GroupInRoleModel.FIELD_ROLE_NAME,FIELD_ROLE_NAME},
                    {GroupInRoleModel.FIELD_RECORD_COUNT,FIELD_RECORD_COUNT}              
                };
                return _GroupInRoleDAO.GetAllGroupInRoleByGroupId(groupInRoleId, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }






        public List<GroupInRoleModel> GetAllGroupInRoleByRoleId(int roleId)
        {
            try
            {
                _GroupInRoleDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {  
               {GroupInRoleModel.FIELD_GROUP_IN_ROLE_ID,FIELD_GROUP_IN_ROLE_ID},
                    {GroupInRoleModel.FIELD_GROUP_ID,FIELD_GROUP_ID},
                    {GroupInRoleModel.FIELD_ROLE_ID,FIELD_ROLE_ID},  
                    {GroupInRoleModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {GroupInRoleModel.FIELD_IS_ACTIVE,FIELD_IS_ACTIVE},
                    {GroupInRoleModel.FIELD_DATE_CREATED,FIELD_DATE_CREATED},
                    {GroupInRoleModel.FIELD_DATE_MODIFIED,FIELD_DATE_MODIFIED},
                    {GroupInRoleModel.FIELD_GROUP_NAME,FIELD_GROUP_NAME},
                    {GroupInRoleModel.FIELD_GROUP_CODE,FIELD_GROUP_CODE},
                    {GroupInRoleModel.FIELD_ROLE_NAME,FIELD_ROLE_NAME},
                    {GroupInRoleModel.FIELD_RECORD_COUNT,FIELD_RECORD_COUNT}             
                };
                return _GroupInRoleDAO.GetAllGroupInRoleByRoleId(roleId, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }


    }
}
